
const http = require('http')
const Router = require('./router')

function Application(){
    this.router = new Router()  //创建应用同时创建一个路由系统
}
Application.prototype.get = function(pathname,...handlers){
    // 将路由存入router
    this.router.get(pathname,handlers)
}
Application.prototype.listen = function(){
    const server = http.createServer((req,res)=>{
        // 当路由系统找不到改路径匹配，返回找不到
        function done(){
            res.end(`cannot  ${req.method} ${req.url}`)
        }
        this.router.handle(req,res,done)

    })
    server.listen(...arguments)
}
module.exports = Application



